package com.qidianit.task.controller;

import com.qidianit.task.pojo.Task;
import com.qidianit.task.service.TaskService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author gfdycxy
 * @Company cxy
 * @Description
 * @Time 2024/9/11 11:17
 */
@RestController
@CrossOrigin
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 通过projectId和parentId查询任务列表
     *
     * @param projectId
     * @param parentId  0 说明是查询一级任务
     * @return
     */
    @GetMapping("/list")
    public QdResult list(String projectId, Long parentId) {
        return taskService.list(projectId, parentId);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody Task task) {
        return taskService.save(task);
    }
    @GetMapping("/selectByTaskId")
    public QdResult selectByTaskId(String taskId){
        return taskService.selectByTaskId(taskId);
    }
    @GetMapping("/get")
    public QdResult get(Long taskId){
        return taskService.queryById(taskId);
    }
    @PutMapping("/edit")
    public QdResult edit(@RequestBody Task task){return taskService.edit(task);}
    @DeleteMapping("/delete")
    public QdResult deleteTask(Long taskId){
        return taskService.deleteTask(taskId);
    }
    @DeleteMapping("/deletes")
    public QdResult deleteTaskByIds(Long[] taskId){
        return taskService.deleteTaskByIds(taskId);
    }
    @GetMapping("/count")
    public QdResult count(Long taskId){
        return taskService.count(taskId);
    }
}